﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Soussous.Business;
using Soussous.DAO;
using Soussous.DAO.Connection;
using Soussous.DAO.Impl;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace Soussous.Units
{
    [TestFixture]
    public class TestUser
    {
        [Test]
        public void TestListUser() 
        {
            var test = UserDAO.getInstance().getAllUser();
            Assert.IsNotEmpty(test, "Ohhhh");
        }
        
        [Test]
        public void TestSearchMailUser()
        {
            var test = UserDAO.getInstance().searchMailUser("bob@gmail.com");
            Assert.That(test,Is.True);
        }
        
        [Test]
        public void TestAuthenticate()
        {
            User user = UserDAO.getInstance().authenticate("bob@gmail.com","12345");
            Assert.IsNotNull(user, "L'utilisateur Bob doit pouvoir s'authentifier");
            var test1 = UserDAO.getInstance().authenticate("oooooo@gmail.com", "12345");
            Assert.IsNull(test1, "coucouc");
        }
        [Test]
        public void TestInsertUser()
        {
            User u = new User();
            u.Email = "test@test.fr";
            u.Password = "1111";
            u.Lastname = "Test2";
            u.Firstname = "Test3";
            UserDAO.getInstance().insert(u);
            var test = UserDAO.getInstance().searchMailUser("test@test.fr");
            Assert.IsTrue(test, "coucou");
        }
        [Test]
        public void TestUpdateUserById()
        {
            User user = new User();
			user.Email= "bobo@gmail.com";
			user.Firstname = "bobo";
			user.Lastname = "bobo";
			user.Password = "bobo";
            UserDAO.getInstance().updateUserById(3, user);
            var test = UserDAO.getInstance().searchMailUser("bobo@gmail.com");
			Assert.IsTrue(test,"Email non trouvé");
        }

        [Test]
        public void TestDeleteUserById()
        {
            User u = new User();
            u.Email = "testox@test.fr";
            u.Password = "1111";
            u.Lastname = "Test2";
            u.Firstname = "Test3";
            UserDAO.getInstance().insert(u);
            UserDAO.getInstance().deleteUserById(u.Id);
            var test = UserDAO.getInstance().searchMailUser("testox@test.fr");
            Assert.IsFalse(test, "L'utilisateur n'a pas été supprimé");
        }

    }
}
